include_directories(include)

set(SRCS src/mock_span_context.cpp
         src/mock_span.cpp
         src/in_memory_recorder.cpp
         src/json_recorder.cpp
         src/base64.cpp
         src/propagation.cpp
         src/utility.cpp
         src/json.cpp
         src/tracer.cpp
         src/tracer_factory.cpp)

if (BUILD_SHARED_LIBS)
  add_library(opentracing_mocktracer SHARED ${SRCS} src/dynamic_load.cpp)
  target_include_directories(opentracing_mocktracer INTERFACE "$<INSTALL_INTERFACE:include/>")
  set_target_properties(opentracing_mocktracer PROPERTIES VERSION ${OPENTRACING_VERSION_STRING}
                                               SOVERSION ${OPENTRACING_VERSION_MAJOR})
  target_link_libraries(opentracing_mocktracer PUBLIC opentracing)
  target_compile_definitions(opentracing_mocktracer PRIVATE OPENTRACING_MOCK_TRACER_EXPORTS)
  install(TARGETS opentracing_mocktracer
          COMPONENT DIST
          EXPORT OpenTracingTargets
          LIBRARY DESTINATION ${LIB_INSTALL_DIR}
          ARCHIVE DESTINATION ${LIB_INSTALL_DIR})

  
endif()

if (BUILD_STATIC_LIBS)
  add_library(opentracing_mocktracer-static STATIC ${SRCS})
  # Windows generates a lib and dll files for a shared library. using the same name will override the lib file generated by the shared target
  if (NOT WIN32)
    set_target_properties(opentracing_mocktracer-static PROPERTIES OUTPUT_NAME opentracing_mocktracer)
  endif()
  target_compile_definitions(opentracing_mocktracer-static PUBLIC OPENTRACING_MOCK_TRACER_STATIC)
  target_include_directories(opentracing_mocktracer-static INTERFACE "$<INSTALL_INTERFACE:include/>")
  target_link_libraries(opentracing_mocktracer-static opentracing-static)
  install(TARGETS opentracing_mocktracer-static EXPORT OpenTracingTargets
	  ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
endif()

install(DIRECTORY include/opentracing DESTINATION include
            FILES_MATCHING PATTERN "*.h")

# ==============================================================================
# Testing

include(CTest)
if(BUILD_TESTING)
  add_subdirectory(test)
endif()
